#pragma once
#include "glib.h"
#include "bytecode.h"
#include "structs.h"

typedef struct tagSearch
{
	int (*func)(u8*);	// match criteria
	int size;			// size of a symbol to compare
} tag_search;

int find_bytes (LPVOID ps, int ls, LPVOID pb, int lb, int mode, tag_search *tag);

class CSearch
{
public:
	CSearch(void);
	~CSearch(void);

	void Reset();

	inline tag_search* GetSearchMethod() {return tag;}
	inline LPVOID GetSearchData() {return search_data;}
	inline int GetSearchSize() {return search_size;}
	inline GString GetSearchString() {return search_str;}
	inline GString GetSearchHex() {return search_hex;}
	inline GString GetSearchRel() {return search_rel;}

private:
	// last search reference
	GString search_str,	// string search
		search_hex,		// hex search
		search_rel;		// relative search
	// reference binary buffer
	LPVOID search_data;
	// size of the buffer
	int search_size;
	// last search method used
	tag_search *tag;
public:
	// relative search data
	std::vector<relation> vRelativeOffsets;

public:
	enum CompareType
	{
		CT_NOCASE_U8,	// case insensitive, byte - no bytecode allowed
		CT_NOCASE_U16,	// case insensitive, wide - no bytecode allowed
		CT_HEX			// case sensitive, bytecode, and hex use this
	};

	// data managers
	int SetSearchHex(GString hex);
	int SetSearchExpression(GString expression, bool match_case, int charmode, int binmode);

	void CreateRelativeSearchString(LPCTSTR string);

	// main window helpers
	int find(LPVOID s1, int s1len, LPVOID s2, int s2len, CompareType type);
};
